package cycling.taxi.com.parse;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;

import cycling.taxi.com.bean.HistoryInfo;
import cycling.taxi.com.bean.PositionInfo;
import cycling.taxi.com.bean.UserVerhicle;

/**
 * 解析工具类
 */

public class ParseTraject {
    public static ArrayList<PositionInfo> positionInfos(String json) throws Exception{
        ArrayList<PositionInfo> positionInfos=new ArrayList<PositionInfo>();
        JSONArray beanJson=new JSONArray(json);
        System.out.print("长度："+beanJson.length());
        for (int i=0;i<beanJson.length();i++){
            JSONObject item = beanJson.getJSONObject(i);
            double longitude= item.getDouble("longitude");
            double latitude= item.getDouble("latitude");
            PositionInfo info=new PositionInfo(longitude,latitude);
            positionInfos.add(info);
        }

        return positionInfos;
    }
    public static ArrayList<HistoryInfo> historyInfos(String json) throws Exception{
        ArrayList<HistoryInfo> infos=new ArrayList<HistoryInfo>();
        JSONArray beanJson=new JSONArray(json);
        System.out.print("长度："+beanJson.length());
        for (int i=0;i<beanJson.length();i++){
            JSONObject item = beanJson.getJSONObject(i);
            String time= item.getString("time");
            String time_durtion=item.getString("time_durtion");
           String licheng=item.getString("licheng");
            String useTime=item.getString("useTime");
             String speed=item.getString("speed");
            String maxSpeed=item.getString("maxSpeed");
            HistoryInfo info=new HistoryInfo(time,time_durtion,licheng,useTime,speed,maxSpeed);
            infos.add(info);
        }

        return infos;
    }

}
